﻿
@model DingTalkAgent.Model.T_Customer
@{
    ViewBag.Title = "Index";
    Layout = null;
}
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title style="color:#ffffff">新增客户</title>
    <meta name="HandheldFriendly" content="True">
    <meta name="MobileOptimized" content="320">
    <meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no">
    <meta http-equiv="cleartype" content="on">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-title" content="">
    <meta name="format-detection" content="telephone=no">
    <meta name="format-detection" content="email=no">
    @Html.Partial("_Common")
    <style>
        .register form {
    padding: 20px 50px 40px 50px;
    -moz-border-radius: 8px;
    -webkit-border-radius: 8px;
    border-radius: 8px;
    -moz-box-shadow: 0 1px 5px 0 rgba(0,0,0,.3);
    -webkit-box-shadow: 0 1px 5px 0 rgba(0,0,0,.3);
    box-shadow: 0 1px 5px 0 rgba(0,0,0,.3);
    text-align: center;
     height:100%;
}
        .register {
        height:100%;
        }
.register form h2 {
    margin-bottom: 25px;
    padding-bottom: 15px;
    /*background: url(../img/pencil.png) 70px 6px no-repeat;*/
    border-bottom: 2px dotted #bbb;
    font-size: 30px;
    font-weight: 400;
    text-align: center;
}

.register form .input {
    width: 97%;
    height: 42px;
    background: #fcfcfc;
    border: 1px solid #ddd;
    -moz-border-radius: 2px;
    -webkit-border-radius: 2px;
    border-radius: 2px;
    -moz-box-shadow: 0 1px 3px 0 rgba(0,0,0,.1) inset;
    -webkit-box-shadow: 0 1px 3px 0 rgba(0,0,0,.1) inset;
    box-shadow: 0 1px 3px 0 rgba(0,0,0,.1) inset;
    font-family: 'PT Sans', Helvetica, Arial, sans-serif;
    color: #888;
    font-size: 18px;
}

.register form .input:focus {
    border: 1px solid #ccc;
    -moz-box-shadow: none;
    -webkit-box-shadow: none;
    box-shadow: none;
}

.register form label {
    margin: 7px 0 10px 5px;
    font-size: 16px;
    text-align: left;
}

.register form label span {
    font-style: italic;
}

.register form input:-moz-placeholder { color: #aaa; }
.register form input:-ms-input-placeholder { color: #aaa; }
.register form input::-webkit-input-placeholder { color: #aaa; }

.register form button {
    cursor: pointer;
    width: 60%;
    height: 42px;
    margin-top: 25px;
    padding: 0;
    background: #eb4141;
    -moz-border-radius: 3px;
    -webkit-border-radius: 3px;
    border-radius: 3px;
    border: 0;
    -moz-box-shadow: 0 15px 30px 0 rgba(255,255,255,.1) inset;
    -webkit-box-shadow: 0 15px 30px 0 rgba(255,255,255,.1) inset;
    box-shadow: 0 15px 30px 0 rgba(255,255,255,.1) inset;
    font-family: 'PT Sans', Helvetica, Arial, sans-serif;
    font-size: 16px;
    font-weight: 400;
    color: #fff;
    text-shadow: 0 1px 2px rgba(0,0,0,.1);
    -o-transition: all .2s;
    -moz-transition: all .2s;
    -webkit-transition: all .2s;
    -ms-transition: all .2s;
}

.register form button:hover {
    -moz-box-shadow: 0 -15px 30px 0 rgba(255,255,255,.05) inset;
    -webkit-box-shadow: 0 -15px 30px 0 rgba(255,255,255,.05) inset;
    box-shadow: 0 -15px 30px 0 rgba(255,255,255,.05) inset;
}

.register form button:active {
    -moz-box-shadow:
        0 -15px 30px 0 rgba(255,255,255,.05) inset,       
        0 5px 8px 0 rgba(0,0,0,.1) inset;
    -webkit-box-shadow:
        0 -15px 30px 0 rgba(255,255,255,.05) inset,       
        0 5px 8px 0 rgba(0,0,0,.1) inset;
    box-shadow:
        0 -15px 30px 0 rgba(255,255,255,.05) inset,       
        0 5px 8px 0 rgba(0,0,0,.1) inset;
}
    </style>
</head>
<body>
    <div class="register span6">
        <form id="editForm" action="" method="post" onsubmit="return false">
            <input type="text" class="input" id="name" name="name" aria-required="true" placeholder="客户名称...">
            <input type="text" class="input" id="telephone" name="telephone" aria-required="true" placeholder="联系方式...">
            <input type="text" class="input" id="address" name="address" aria-required="true" placeholder="地址...">
            <select name="source" id="source" class="input">
                <option value="0">如何得知我们...</option>
                <option value="1">网络</option>
                <option value="2">宣传册</option>
                <option value="3">病友推荐</option>
                <option value="4">医院推荐</option>
            </select>
            <textarea id="txt_intentService" name="intentService" class="input" aria-required="true" style="height:70px;" placeholder="意向服务内容和机构..."></textarea>
            @*<select id="com_SaleUserId" class="input" name="saleUserId">
                <option value="0">所属销售...</option>
            </select>*@
            <select name="saleUserId" id="com_SaleUserId" class="input"></select>
            <button id="btn_Save" type="submit">保存</button>
            
        </form>
    </div>
    <script type="text/javascript" charset="utf-8">
        $(document).ready(function () {
            InintSaleUser();
            jQuery.validator.addMethod("phone", function(value, element) {
                var telephone = $("#telephone").val();
                var mobileRule = /^(13[0-9]|14[5|7]|15[0|1|2|3|5|6|7|8|9]|18[0-9]|170)\d{8}$/;
                var telephoneRule = /^\d{3,4}-?\d{7,9}$/;

                if (!mobileRule.test(telephone)||!telephoneRule.test(telephone)) {
                    return false;
                } else {
                    return true;
                }
            }, "联系方式格式不对哦");
            jQuery.validator.addMethod("sourceNumber", function(value, element) {
                var number = $("#source").val();
                if (number==0) {
                    return false;
                } else {
                    return true;
                
                }
            }, "请选择如何知道我们");
            jQuery.validator.addMethod("saleUserIdNumber", function(value, element) {
                var number = $("#com_SaleUserId").val();
                if (number==0) {
                    return false;
                } else {
                    return true;
                
                }
            }, "请选择所属销售");
            //验证
            Validater = $("form").validate({
                rules: {
                    name: {
                        required: true,
                        minlength: 2
                    },
                    telephone: {
                        required: true,
                        //minlength: 5
                        phone:true
                    },
                    address: {
                        required: true
                    },
                    intentService: {
                        required: true
                    },
                    source:{
                        sourceNumber:true
                    },
                    saleUserId:{
                        saleUserIdNumber:true
                    }

                },
                messages: {
                    name: {
                        required: '<span style="color:red;font-size:14px;font-style:normal">请输入客户名称</span>',
                        minlength: '<span style="color:red;font-size:14px;font-style:normal">客户名称必须两个字符以上</span>',
                    },
                    telephone: {
                        required: '<span style="color:red;font-size:14px;font-style:normal">请输入客户的联系方式</span>',
                        phone: '<span style="color:red;font-size:14px;font-style:normal">请输入正确的联系方式</span>'
                    },
                    address: {
                        required: '<span style="color:red;font-size:14px;font-style:normal">请输入联系地址</span>'
                    },
                    intentService: {
                        required: '<span style="color:red;font-size:14px;font-style:normal">请输入意向内容</span>'
                    },
                    source: {
                        sourceNumber: '<span style="color:red;font-size:14px;font-style:normal">请选择如何知道我们</span>'
                    },
                    saleUserId: {
                        saleUserIdNumber: '<span style="color:red;font-size:14px;font-style:normal">请选择所属销售</span>'
                    }
                }
            });
            $("#btn_Save").click(function () {
                if (Validater.form()) {
                    $.ajax({
                        type: "POST",
                        url: "/Customer/Save",
                        dataType: "JSON",
                        data: $('#editForm').serializeArray(),
                        success: function (data) {
                            if (data.status) {
                                alert(data.msg);
                                setTimeout(function () {
                                    window.location.href = '/mobile/Customer/Customer';
                                }, 500);
                            }
                        }, error: function () {
                            alert(data.msg);
                        }
                    });
                }
            });
        });
        function InintSaleUser() {
            $("#com_SaleUserId").empty();//清空select列表数据
            $.ajax({
                type: "POST",
                url: "/Customer/GetSaleUserList",
                dataType: "JSON",
                data: {},
                success: function (data) {
                    $("#com_SaleUserId").append("<option value='0'>所属销售...</option>");//添加第一个option值
                    $.each(data, function (i, obj) {
                        $("#com_SaleUserId").append("<option value='" + obj.id + "'>" + obj.name + "</option>");
                    });
                }, error: function () {
                    //alertLayer("获取数据失败", "error");
                }
            });
        }
    </script>
</body>
</html>
